package com.bw.zcb.mvp.view;

import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;


import androidx.fragment.app.FragmentTransaction;

import com.bw.zcb.R;
import com.bw.zcb.fragment.LiveFragment;
import com.bw.zcb.fragment.MineFragment;

import com.bw.zcb.mvp.view.people.PeopleFragment;
import com.bw.zcb.mvp.view.video.VideoFragment;
import com.bw.zcb.mvp.base.view.BaseActivity;
import com.bw.zcb.mvp.contract.FrameContact;
import com.bw.zcb.mvp.di.DaggerFrameComponent;
import com.bw.zcb.mvp.di.FrameModules;
import com.bw.zcb.mvp.presenter.FramePresenter;
import com.bw.zcb.mvp.view.news.NewsFragment;
import com.bw.zcb.widget.BottomButton;

import java.util.Map;

public class BottomButtonActivity extends BaseActivity<FramePresenter> implements FrameContact.IFrameView ,BottomButton.SelectListener {


    private LinearLayout linearCenter;
    private NewsFragment newsFragment;
    private PeopleFragment peopleFragment;
    private VideoFragment videoFragment;
    private LiveFragment liveFragment;
    private MineFragment mineFragment;
    private FragmentTransaction fragmentTransaction;
    private FragmentTransaction fragmentTransaction1;
    private BottomButton news;
    private BottomButton people;
    private BottomButton video;
    private BottomButton live;
    private BottomButton mine;


    @Override
    public View addStatusView() {
        return f(R.id.bottom_layout);
    }

    @Override
    public void onSelect(int id) {
        if (id == R.id.news) {
            StatusView(Color.WHITE);
            people.clearSelect();
            video.clearSelect();
            live.clearSelect();
            mine.clearSelect();
        }
        if (id == R.id.people) {
            StatusView(Color.WHITE);
            news.clearSelect();
            video.clearSelect();
            live.clearSelect();
            mine.clearSelect();
        }
        if (id == R.id.video) {
            StatusView(Color.WHITE);
            news.clearSelect();
            people.clearSelect();
            live.clearSelect();
            mine.clearSelect();
        }
        if (id == R.id.live) {
            StatusView(Color.WHITE);
            news.clearSelect();
            people.clearSelect();
            video.clearSelect();
            mine.clearSelect();
        }
        if (id == R.id.mine) {
            StatusView(Color.RED);
            news.clearSelect();
            people.clearSelect();
            live.clearSelect();
            video.clearSelect();
        }
        fragmentTransaction1 = getSupportFragmentManager().beginTransaction();
        if (newsFragment != null) {
            fragmentTransaction1.hide(newsFragment);
        }
        if (peopleFragment != null) {
            fragmentTransaction1.hide(peopleFragment);
        }
        if (videoFragment != null) {
            fragmentTransaction1.hide(videoFragment);
        }
        if (liveFragment != null) {
            fragmentTransaction1.hide(liveFragment);
        }
        if (mineFragment != null) {
            fragmentTransaction1.hide(mineFragment);
        }
        switch (id) {
            case R.id.news:
                fragmentTransaction1.show(newsFragment);
                break;
            case R.id.people:
                if (peopleFragment == null) {
                    peopleFragment = new PeopleFragment();
                    fragmentTransaction1.add(R.id.linear_center, peopleFragment);
                } else {

                    fragmentTransaction1.show(peopleFragment);

                }
                break;
            case R.id.video:
                if (videoFragment == null) {
                    videoFragment = new VideoFragment();
                    fragmentTransaction1.add(R.id.linear_center, videoFragment);
                } else {
                    fragmentTransaction1.show(videoFragment);
                }
                break;
            case R.id.live:
                if (liveFragment == null) {
                    liveFragment = new LiveFragment();
                    fragmentTransaction1.add(R.id.linear_center, liveFragment);
                } else {

                    fragmentTransaction1.show(liveFragment);
                }
                break;
            case R.id.mine:
                if (mineFragment == null) {
                    mineFragment = new MineFragment();
                    fragmentTransaction1.add(R.id.linear_center, mineFragment);
                } else {
                    fragmentTransaction1.show(mineFragment);

                }
                break;
        }
        fragmentTransaction1.commit();
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_bottom_button;
    }

    @Override
    public void initView() {
        StatusView(Color.WHITE);
        linearCenter = (LinearLayout) findViewById(R.id.linear_center);
        news = (BottomButton) findViewById(R.id.news);
        people = (BottomButton) findViewById(R.id.people);
        video = (BottomButton) findViewById(R.id.video);
        live = (BottomButton) findViewById(R.id.live);
        mine = (BottomButton) findViewById(R.id.mine);
        news.setContent("新闻").setNomalColor(Color.BLACK)
                .setSelColor(Color.RED)
                .setNomalImg(R.drawable.tu1_f)
                .setSelImg(R.drawable.tu1_t)
                .setListener(this::onSelect)
                .setShowPoint(false);
        people.setContent("人民号").setNomalColor(Color.BLACK)
                .setSelColor(Color.RED)
                .setNomalImg(R.drawable.tu2_f)
                .setSelImg(R.drawable.tu2_t)
                .setListener(this::onSelect)
                .setShowPoint(false);
        video.setContent("视频").setNomalColor(Color.BLACK)
                .setSelColor(Color.RED)
                .setNomalImg(R.drawable.tu3_f)
                .setSelImg(R.drawable.tu3_t)
                .setListener(this::onSelect)
                .setShowPoint(false);
        live.setContent("直播").setNomalColor(Color.BLACK)
                .setSelColor(Color.RED)
                .setNomalImg(R.drawable.tu4_f)
                .setSelImg(R.drawable.tu4_t)
                .setListener(this::onSelect)
                .setShowPoint(false);
        mine.setContent("我的").setNomalColor(Color.BLACK)
                .setSelColor(Color.RED)
                .setNomalImg(R.drawable.tu5_f)
                .setSelImg(R.drawable.tu5_t)
                .setListener(this::onSelect)
                .setShowPoint(false);
        newsFragment = new NewsFragment();
        fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.linear_center, newsFragment);
        fragmentTransaction.commit();
    }


    @Override
    public void initData() {

    }

    @Override
    public void inject() {
        DaggerFrameComponent.builder().frameModules(new FrameModules(this)).build().injectFrame(this);
    }

    @Override
    public Void refresh(Map<String, Object> resultmap) {
        return null;
    }
}
